<!--
 * @Author: boyyang
 * @Date: 2022-01-02 19:36:37
 * @LastEditTime: 2022-02-18 21:27:33
 * @LastEditors: boyyang
 * @Description: 
 * @FilePath: \boyyang\src\views\login\components\loginBox.vue
-->

<template>
  <div class="login-box">
    <div class="login-title">{{ props.type ? '登 录' : '注 册' }}</div>
    <div class="input-content">
      <div class="login-account">
        <span>{{ props.type ? '邮箱或登录名' : '邮箱' }}:</span>
        <login-input v-model:text="email" :placeholder="props.type ? '请输入邮箱账号或登录名' : '请输入邮箱账号'" />
      </div>
      <div class="login-password">
        <span>密码 :</span>
        <login-input v-model:text="password" placeholder="请输入账号密码" type="password" />
      </div>
      <div class="login-password" v-show="!props.type">
        <span>重复密码 :</span>
        <login-input v-model:text="repassword" placeholder="请输入账号重复密码" type="password" />
      </div>
    </div>

    <div class="login-btn-groups">
      <login-btn btnText="确 认" @btnClick="login"></login-btn>
    </div>

    <!-- light -->

    <div class="line-wrapper">
      <div class="line"></div>
      <div class="line"></div>
      <div class="line"></div>
      <div class="line"></div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import loginInput from './loginInput.vue'
import loginBtn from './loginBtn.vue'
import { emailReg } from '@/utils/regular'
import { useMessage } from '@/components/message'
import { Ioption } from './types'

interface ILoginBoxProps {
  type?: boolean;
}

interface Emits {
  (e: 'signIn', option: Ioption): void;
  (e: 'signUp', option: Ioption): void;
}

const props = withDefaults(defineProps<ILoginBoxProps>(), {
  type: true
})

const message = useMessage()
const emit = defineEmits<Emits>()

// 邮箱 密码 重复密码
let email = ref<string>('boyyanglove')
let password = ref<string | number>('yzhd45683968yzhd')
let repassword = ref<string | number>('')

// 类型 默认为登录 true 注册为 false
let type = ref<boolean>(true)

// 确认
const login = (): void => {
  if (props.type) { //登录
    // 不为空判断
    if (email.value.trim() === '' || String(password.value).trim() === '') {
      console.log('账号密码为必填项')
      message.warning('账号密码为必填项')
      return
    }

    let option: Ioption = {
      account: email.value,
      password: password.value
    }

    emit('signUp', option)

  } else { // 注册
    // 不为空判断
    if (email.value.trim() === '' || String(password.value).trim() === '' || String(repassword.value) === '') {
      console.log('账号密码为必填项')
      message.warning('账号密码为必填项')
      return
    }

    let option: Ioption = {
      account: email.value,
      password: password.value
    }

    if (emailReg(email.value)) {
      if (password.value === repassword.value) {
        emit('signIn', option)
      } else {
        console.log('密码不一致')
        message.warning('密码不一致')
      }
    } else {
      console.log('邮箱格式不正确')
      message.warning('邮箱格式不正确')
    }
  }
}

</script>

<style scoped lang="scss">
.login-box {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 10px;
  position: relative;
  overflow: hidden;
  border-radius: 5px;

  display: flex;
  align-items: center;
  flex-direction: column;

  .login-title {
    font-family: "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;
    font-size: 20px;
    color: whitesmoke;
    font-weight: 800;
    margin-bottom: 5px;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .login-account,
  .login-password {
    box-sizing: border-box;
    width: 100%;
    height: 65px;
    margin: 5px 0;
    padding: 0 25px;
    display: flex;
    flex-direction: column;

    span {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      font-size: 14px;
      font-weight: bold;
      color: whitesmoke;
      white-space: nowrap;
      margin-bottom: 10px;
    }

    transition: all 1s linear;
  }

  .input-content {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
  }

  .login-btn-groups {
    box-sizing: border-box;
    width: 40%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: absolute;
    bottom: 35px;
  }

  .line-wrapper div:nth-child(1) {
    box-sizing: border-box;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #00b7ff);
    position: absolute;
    top: 0;
    left: -100%;
    animation: move1 4s 1s linear infinite;
  }

  .line-wrapper div:nth-child(2) {
    box-sizing: border-box;
    width: 2px;
    height: 100%;
    background: linear-gradient(180deg, transparent, #1bd1a5);
    position: absolute;
    right: 0;
    top: -100%;
    animation: move2 4s 2s linear infinite;
  }

  .line-wrapper div:nth-child(3) {
    box-sizing: border-box;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, #00e09e, transparent);
    position: absolute;
    bottom: 0;
    left: 100%;
    animation: move3 4s 3s linear infinite;
  }

  .line-wrapper div:nth-child(4) {
    box-sizing: border-box;
    width: 2px;
    height: 100%;
    background: linear-gradient(0deg, transparent, #00b7ff);
    position: absolute;
    left: 0;
    top: 100%;
    animation: move4 4s 4s linear infinite;
  }

  @keyframes move1 {
    50%,
    100% {
      left: 100%;
    }
  }

  @keyframes move2 {
    50%,
    100% {
      top: 100%;
    }
  }

  @keyframes move3 {
    50%,
    100% {
      left: -100%;
    }
  }

  @keyframes move4 {
    50%,
    100% {
      top: -100%;
    }
  }
}

@media screen and (max-width: 500px) {
  .login-box {
    padding: 10px 0;

    .login-account,
    .login-password {
      padding: 0 5px;
    }
  }
}
</style>